home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / XLIB06.ZIP / DEMO2.C < prev    next >
C/C++ Source or Header  |  1993-09-13  |  7KB  |  222 lines

  1. /*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap,  conventional
  6. masked planar bitmap, and video bitmap blits.
  7.  
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include "xlib.h"
  19. #include "xcbitmap.h"
  20. #include "xpbitmap.h"
  21. #include "xvbitmap.h"
  22. #include "xbmtools.h"
  23. #include  "xtext.h"
  24. #include  "xrect.h"
  25. #include  "xrect.h"
  26.  
  27. /* Macro to make pointer parameters model independent */
  28. #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  29.  
  30. char turtle[] = {
  31.     20,30,
  32. /*  |      .       |       .      |       .      |      .       */
  33.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  39.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  40.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  41.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  42.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  43.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  44.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  45.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  46.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  47.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  48.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  49.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  50.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  51.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  52.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  53.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  54.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  61.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  62.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  63.     };
  64.  
  65.  
  66. char far *pbm, far *vbm;
  67. char far *newfnt;
  68.  
  69. char far *
  70. AllocatedSprite(int width, int height, int logical_width, char far * bitmap)
  71. {
  72.     char far * result;
  73.     int size;
  74.  
  75.     pbm = farmalloc(width * height + 2);
  76.     x_bm_to_pbm(bitmap,pbm);
  77.  
  78.     result = farmalloc((width * height * 7) / 2 + 25);
  79.     if (result == 0)
  80.     return(0);
  81.     size = x_compile_bitmap(logical_width, bitmap, result);
  82.  
  83.     return farrealloc(result, size);
  84. }
  85.  
  86.  
  87.  
  88. void load_user_fonts(){
  89.   FILE *f;
  90.   int i; char c;
  91. //  f=fopen("c:\\font.fnt","rb");
  92.   f=fopen("smalbold.fnt","rb");
  93.   newfnt = farmalloc(256*16+4);
  94.   for (i=0;i<256*16+4;i++){
  95.     fread(&c,1,1,f);
  96.     *(newfnt+i)=c;
  97.   }
  98.   fclose(f);
  99.   x_text_init();
  100.   x_register_userfont(newfnt);
  101.   x_set_font(2);
  102. }
  103.  
  104. void
  105. main()
  106. {
  107.     int i,j,k;
  108.  
  109.     double ratio,ratio2;
  110.     struct time pbm_t0,pbm_t1,cbm_t0,cbm_t1,vbm_t0,vbm_t1;
  111.     long vbm_ticks,pbm_ticks,cbm_ticks;
  112.     char far * TurtleSprite;
  113.  
  114.     x_set_mode(X_MODE_320x240,360);
  115.  
  116.     TurtleSprite = AllocatedSprite(20, 30, 90,FARPTR(turtle));
  117.  
  118.     vbm = x_make_vbm(MK_FP(_DS,turtle),&NonVisual_Offs);
  119.     if (!vbm) {
  120.       sound(1000);
  121.       delay(100);
  122.       nosound();
  123.     }
  124.  
  125.     load_user_fonts();
  126.     x_bgprintf(0,0,0,14,0,
  127.       "This is a demo to show the speed difference between");
  128.     x_bgprintf(0,8,0,14,0,
  129.       "compiled, planar and video bitmaps.  The bitmap:");
  130.  
  131.     x_put_cbitmap(140, 18, 0, TurtleSprite);
  132.  
  133.     x_bgprintf(0,48,0,14,0,
  134.       "This demo uses the NON CLIPPED, MASKED versions of");
  135.     x_bgprintf(0,56,0,14,0,
  136.        "       'PBM' and VBM' put functions");
  137.     x_bgprintf(0,78,0,14,0,
  138.       "Press a key to start with PLANAR BITMAP demo");
  139.  
  140.     getch();
  141.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  142.  
  143.  
  144.     gettime(&pbm_t0);
  145.     for (k=0;k<3;k++)
  146.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  147.     for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  148.       x_put_masked_pbm(i*20, j*30, 0, pbm);
  149.     gettime(&pbm_t1);
  150.     pbm_ticks = (((long)pbm_t1.ti_hund
  151.         +((long)pbm_t1.ti_sec*100)
  152.         +((long)pbm_t1.ti_min*6000)) -
  153.         (((long)pbm_t0.ti_hund
  154.         +((long)pbm_t0.ti_sec*100)
  155.         +((long)pbm_t0.ti_min*6000))));
  156.  
  157.  
  158.     x_bgprintf(0,0,0,14,0,
  159.       "Press a key to start with the VIDEO BITMAP demo");
  160.  
  161.     getch();
  162.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  163.  
  164.  
  165.     gettime(&vbm_t0);
  166.     for (k=0;k<3;k++)
  167.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  168.     for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  169.       x_put_masked_vbm(i*20, j*30, 0, vbm);
  170.     gettime(&vbm_t1);
  171.     vbm_ticks = (((long)vbm_t1.ti_hund
  172.         +((long)vbm_t1.ti_sec*100)
  173.         +((long)vbm_t1.ti_min*6000)) -
  174.         (((long)vbm_t0.ti_hund
  175.         +((long)vbm_t0.ti_sec*100)
  176.         +((long)vbm_t0.ti_min*6000))));
  177.  
  178.  
  179.  
  180.  
  181.     x_bgprintf(0,0,0,14,0,
  182.       "Now Press a key to start with COMPILED BITMAP demo");
  183.  
  184.     getch();
  185.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  186.  
  187.     gettime(&cbm_t0);
  188.     for (k=0;k<3;k++)
  189.       for (j=0;j<(ScrnPhysicalHeight/30);j++)
  190.     for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  191.       x_put_cbitmap(i*20, j*30, 0, TurtleSprite);
  192.     gettime(&cbm_t1);
  193.     cbm_ticks = (((long)cbm_t1.ti_hund
  194.         +((long)cbm_t1.ti_sec*100)
  195.         +((long)cbm_t1.ti_min*6000)) -
  196.         (((long)cbm_t0.ti_hund
  197.         +((long)cbm_t0.ti_sec*100)
  198.         +((long)cbm_t0.ti_min*6000))));
  199.     if (cbm_ticks==0){
  200.       cbm_ticks=1;
  201.       pbm_ticks+=1;
  202.       vbm_ticks+=1;
  203.     }
  204.     ratio = pbm_ticks*(double)1.0/cbm_ticks;
  205.     ratio2 = vbm_ticks*(double)1.0/cbm_ticks;
  206.  
  207.     x_set_font(1);
  208.     x_bgprintf(0,ScrnPhysicalHeight-30,0,14,0,
  209.       "s/100 PBM=%ld VBM=%ld CBM=%ld - %4.1lf:%4.1lf:1",
  210.       pbm_ticks,vbm_ticks,cbm_ticks,ratio,ratio2);
  211.     x_set_font(2);
  212.     x_bgprintf(0,ScrnPhysicalHeight-16,0,14,0,
  213.       "Timing is rough but still,  quite impressive ! ");
  214.     x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
  215.       "Clipping slows things down considerably. ");
  216.  
  217.  
  218.     getch();
  219.     x_text_mode();
  220. }
  221.  
  222.